<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "library_book".
 *
 * @property int $id
 * @property string|null $author
 * @property string $title
 * @property int|null $year
 * @property string|null $annotation
 */
class LibraryBook extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'library_book';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['title'], 'required'],
            [['year', 'condition_id', 'collection_id', 'bbk_id', 'udk_id'], 'integer'],
            [['annotation', 'comment'], 'string'],
            [['author', 'inventory_number', 'publisher'], 'string', 'max' => 255],
            [['title'], 'string', 'max' => 400],
            [['keywords', 'condition_clarification'], 'string', 'max' => 512],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'author' => 'Автор',
            'title' => 'Название',
            'year' => 'Год',
            'annotation' => 'Аннотация',
            'inventory_number' => 'Инвентарный шифр',
            'keywords' => 'Ключевые слова',
            'comment' => 'Дополнительная информация',
            'condition_id' => 'Сохранность',
            'condition_clarification' => 'Уточнение сохранности',
            'collection_id' => 'Коллекция',
            'bbk_id' => 'ББК',
            'udk_id' => 'УДК',
            'publisher' => 'Издательство',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCondition()
    {
        return $this->hasOne(LibraryCondition::className(), ['id' => 'condition_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCollection()
    {
        return $this->hasOne(LibraryCollection::className(), ['id' => 'collection_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBbk()
    {
        return $this->hasOne(LibraryBbk::className(), ['id' => 'bbk_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUdk()
    {
        return $this->hasOne(LibraryUdk::className(), ['id' => 'udk_id']);
    }


}
